ArrayList & LinkedList

    ArrayList
Member.java
package collection;
public class Member implements Comparable<Member>{
private int memberId;
private String memberName;
public Member(int memberId, String memberName) {
this.memberId=memberId;
this.memberName=memberName;
}
public int getMemberId() {
return memberId;
}
public void setMemberId(int memberId) {
this.memberId=memberId;
}
public String getMemberName() {
return memberName;
}
public void setMemberName(String memberName) {
this.memberName=memberName;
}
@Override
public String toString() {
return memberName+" "+memberId+" .";
}
@Override
public int hashCode(){
return memberId;
}
@Override
public boolean equals(Object obj){
if(obj instanceof Member){
Member member=(Member) obj;
if(this.memberId==member.memberId)return true;
else return false;
}
return false;
}
@Override
public int compareTo(Member member){
return (this.memberId-member.memberId);
}
}
MemberArrayList.java
package collection.arraylist;
import java.util.ArrayList;
import collection.Member;
public class MemberArrayList {
private ArrayList<Member> arrayList;
public MemberArrayList() {
arrayList=new ArrayList<Member>();
}
public void addMember(Member member) {
arrayList.add(member);
}
public boolean removeMember(int memberId) {
for(int i=0;i<arrayList.size();i++) {
Member member=arrayList.get(i);
int tempId=member.getMemberId();
if(tempId==memberId) {
arrayList.remove(i);
return true;
}
}
System.out.println(memberId+" .");
return false;
}
public void showAllMember() {
for(Member member:arrayList) {
System.out.println(member);
}
System.out.println();
}
}
MemberArrayListTest.java
package collection.arraylist;
import collection.Member;
public class MemberArrayListTest {
public static void main(String[] args) {
MemberArrayList memberArrayList=new MemberArrayList();
Member memberLee=new Member(1001,"");
Member memberSon=new Member(1002,"");
Member memberPark=new Member(1003,"");
Member memberHong=new Member(1004,"");
memberArrayList.addMember(memberLee);
memberArrayList.addMember(memberSon);
memberArrayList.addMember(memberPark);
memberArrayList.addMember(memberHong);
memberArrayList.showAllMember();
memberArrayList.removeMember(memberHong.getMemberId());
memberArrayList.showAllMember();
}
}
    LinkedList
LinkedListTest.java
package collection.arraylist;
import java.util.LinkedList;
public class LinkedListTest {
public static void main(String[] args) {
LinkedList<String> myList=new LinkedList<String>();
myList.add("A");
myList.add("B");
myList.add("C");
System.out.println(myList);
myList.add(1,"D");
System.out.println(myList);
myList.addFirst("0");
System.out.println(myList);
System.out.println(myList.removeLast());
System.out.println(myList);
}
}